<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script src="../js/vue.js"></script>
		<div id="app">
			<cpn></cpn>
			<cpn></cpn>
			<cpn></cpn>
		</div>
		<template id="cpn">
			<div>
				<h1>当前计数：{{counter}}</h1>
				<button @click="add">+</button>
				<button @click="sub">-</button>
			</div>
		</template>
		<script>
			// 调用组件的时候 是调用data函数，每次调用data函数的时候都会return一个新的
			// 对象，所以组件中的对象互不干扰
			Vue.component("cpn",{
				template:"#cpn",
				data(){
					return{
						counter:0
					}
				},
				methods:{
					add(){
						this.counter++
					},
					sub(){
						this.counter--
					}
				}
			})
			var app = new Vue({
				el: '#app',
				data: {

				},
				methods: {

				}
			})
		</script>
	</body>
</html>
